package com.campus.customer.controller;

import com.campus.common.bean.common.Resp;
import com.campus.customer.bean.PointsRecordQueryParam;
import com.campus.customer.service.PointsRecordService;
import com.campus.customer.service.SessionService;
import com.campus.common.bean.common.Pagination;
import com.campus.customer.vo.PointsRecordVo;
import com.campus.customer.vo.UserInfoVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 积分记录表 前端控制器
 * </p>
 *
 * @author ZhaoYuJie
 * @since 2025-04-02
 */
@RestController
@RequestMapping("/pointsRecord")
@Api(tags = "积分记录管理")
public class PointsRecordController {

    @Autowired
    private PointsRecordService pointsRecordService;

    @Autowired
    private SessionService sessionService;

    @PostMapping("/getPointsRecordPage")
    @ApiOperation("分页查询积分记录")
    public Resp<Pagination<PointsRecordVo>> getPointsRecordPage(@RequestBody PointsRecordQueryParam queryParam) {
        // 获取当前登录用户信息
        UserInfoVo userInfo = sessionService.getUserInfo();
        
        // 设置查询条件为当前用户
        queryParam.setUserId(userInfo.getId());
        
        // 查询积分记录
        PageInfo<PointsRecordVo> pageInfo = pointsRecordService.getPointsRecordPage(queryParam);
        
        return Resp.successPageable(pageInfo);
    }

}
